# Makefile for mcmas+
# --------------------------------------------------

# Cudd Directory
CUDD	= ../CUDD/
DDDMP 	= ../DDDMP/

# ---- COMPILERS ----
# C++ compiler
CPP     = g++
# C compiler
CC 	= gcc
# CC compilation flags
CCFLAGS	= -g
# CPP compilation flags
CPPFLAGS = -g -W -Wall -Wconversion -lm
INCLUDE = -Iinclude -I$(CUDD)include -I$(DDDMP)#-I$(CUDD)obj
# ---- END COMPILERS ----

GRAMMAR		= parser/nssis
LEXFILE 	= parser/nssis
DRIVER		= parser/mcmas-driver
SYNTAXCHECK	= parser/syntaxcheck
UTILITIES	= utilities/utilities
TYPES		= utilities/types
MAIN		= main
LEX			= flex
YACC		= /usr/local/bison-2.3/bin/bison

OFF = -DREORDER_OFF
FORCED = -DFORCED_REORDER
AUTO = -DAUTO_REORDER


CUDDLIBS = $(CUDD)obj/cuddObj.o $(CUDD)obj/libobj.a $(CUDD)cudd/libcudd.a $(CUDD)mtr/libmtr.a $(CUDD)st/libst.a $(CUDD)util/libutil.a $(CUDD)epd/libepd.a

DDMPLIBS = $(DDDMP)libdddmp.a $(CUDD)cudd/libcudd.a $(CUDD)mtr/libmtr.a $(CUDD)st/libst.a $(CUDD)util/libutil.a $(CUDD)epd/libepd.a

OBJECTS = $(TYPES).o parser/lex.yy.o $(GRAMMAR).o $(DRIVER).o $(SYNTAXCHECK).o $(UTILITIES).o #bdd/bdd.o bdd/bdduniform.o 

#mcmas : $(OBJECTS) $(MAIN).cc
#	$(CPP) $(CPPFLAGS) $(INCLUDE) $(CUDDLIBS) $(DDMPLIBS) $(OBJECTS) -o mcmas $(MAIN).cc $(OFF)

mcmas : mcmas_off

mcmas_off : $(OBJECTS) $(MAIN).cc
	$(CPP) $(CPPFLAGS) $(MAIN).cc -o mcmas 		$(INCLUDE) $(CUDDLIBS) $(DDMPLIBS) $(OFF) $(OBJECTS)

mcmas_forced : $(OBJECTS) $(MAIN).cc
	$(CPP) $(CPPFLAGS) $(MAIN).cc -o mcmas 		$(INCLUDE) $(CUDDLIBS) $(DDMPLIBS) $(FORCED) $(OBJECTS)

mcmas_auto : $(OBJECTS) $(MAIN).cc
	$(CPP) $(CPPFLAGS) $(MAIN).cc -o mcmas 		$(INCLUDE) $(CUDDLIBS) $(DDMPLIBS) $(AUTO) $(OBJECTS)


#mcmas_forced : $(OBJECTS) $(MAIN).cc
#	$(CPP) $(CPPFLAGS) $(INCLUDE) $(CUDDLIBS) $(OBJECTS) -o mcmas $(MAIN).cc $(FORCED)
	
#mcmas_auto : $(OBJECTS) $(MAIN).cc
#	$(CPP) $(CPPFLAGS) $(INCLUDE) $(CUDDLIBS) $(OBJECTS) -o mcmas $(MAIN).cc $(AUTO)

#test: $(OBJECTS)
#	$(CPP) $(CPPFLAGS) testdddmp.c -o testdddmp $(INCLUDE) $(CUDDLIBS) $(DDMPLIBS) $(OFF) 

mcmas_test : $(OBJECTS) $(MAIN).cc
	$(CPP) $(CPPFLAGS) $(MAIN).cc -o mcmas		$(INCLUDE) $(CUDDLIBS) $(DDMPLIBS) $(OFF) $(OBJECTS)

parser/lex.yy.o: $(LEXFILE).ll $(GRAMMAR).yy
	$(LEX) -oparser/lex.yy.c $(LEXFILE).ll

# For old bison (e.g. v. 1.28)
#	$(YACC) -d $(GRAMMAR).y -o $(GRAMMAR).cc
# For recent bison (e.g. v. 1.35 or above)
	$(YACC) --defines=$(GRAMMAR).hh $(GRAMMAR).yy -o $(GRAMMAR).cc
	$(CPP) $(CPPFLAGS) $(INCLUDE)  -c parser/lex.yy.c -o parser/lex.yy.o
	
#parser/syntaxchecks.o: parser/syntaxchecks.cc parser/syntaxchecks.cc
#	$(CPP) $(CPPFLAGS) $(INCLUDE) -c parser/syntaxchecks.cc -o parser/syntaxchecks.o

$(GRAMMAR).o: include/utilities.hh include/types.hh $(LEXFILE).ll $(GRAMMAR).yy
	$(CPP) $(CPPFLAGS) $(INCLUDE) -c $(GRAMMAR).cc -o $(GRAMMAR).o

$(SYNTAXCHECK).o: include/utilities.hh include/types.hh $(SYNTAXCHECK).cc
	$(CPP) $(CPPFLAGS) $(INCLUDE) -c $(SYNTAXCHECK).cc -o $(SYNTAXCHECK).o

$(UTILITIES).o: include/utilities.hh $(UTILITIES).cc
	$(CPP) $(CPPFLAGS) $(INCLUDE) -c $(UTILITIES).cc -o $(UTILITIES).o

$(TYPES).o: include/types.hh $(TYPES).cc
	$(CPP) $(CPPFLAGS) $(INCLUDE) -c $(TYPES).cc -o $(TYPES).o

$(DRIVER).o: $(DRIVER).cc 
	$(CPP) $(CPPFLAGS) $(INCLUDE) -c $(DRIVER).cc -o $(DRIVER).o 

#bdd/bdd.o: bdd/bdd.cc bdd/bdd.hh
#	$(CPP) $(CPPFLAGS) $(INCLUDE) -c bdd/bdd.cc -o bdd/bdd.o

#bdd/bdduniform.o: bdd/bdduniform.cc bdd/bdduniform.hh bdd/bdd.hh bdd/bdd.cc
#	$(CPP) $(CPPFLAGS) $(INCLUDE) $(CPPFLAGS) -c bdd/bdduniform.cc -o bdd/bdduniform.o


.PHONY : clean
clean:
	rm -rf $(OBJECTS) parser/lex.yy.c parser/location.hh parser/position.hh parser/stack.hh $(GRAMMAR).hh $(GRAMMAR).cc 

.PHONY : reallyclean
reallyclean: clean
	rm -rf mcmas
